package com.ofek.applicationbase.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;



public class DebugUtils {

	private static final ExecutorService es = Executors.newSingleThreadExecutor();

	public static void printObject(final Object obj) {
		System.out.println(toString(obj));
	}
	public static String toString(final Object obj) {
		final StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(obj);
		stringBuilder.append('\n');
		if (obj == null) return stringBuilder.toString();
	
		final Class<? extends Object> class1 = obj.getClass();
		for (final Field f : class1.getDeclaredFields()) {
			if (Modifier.isStatic(f.getModifiers())) continue;
			//if (!f.getDeclaringClass().isPrimitive()) continue;
			final boolean accessible = f.isAccessible();
			f.setAccessible(true);
			stringBuilder.append(f.getName());
			stringBuilder.append(" : ");
			try {
				stringBuilder.append(f.get(obj));
			} catch (final Exception e) {
				stringBuilder.append("Couldnt evluate get on this field");
			}
			stringBuilder.append('\n');
			f.setAccessible(accessible);
		}
		return stringBuilder.toString();
	}

}
